@extends('/welcome')

@section('zhong_content')
  <div class="webz c_clearfix shoppingcart_con" data-role="cart"> 
   <p class="shopcart_tit">我的购物车</p> 
   <div class="cart_con"> 
    <ul class="cart_con_tit c_clearfix"> 
     <li class="tit_check"><input checked="checked" data-role="all" type="checkbox" /><label>全选</label></li> 

     <li class="tit_meg"></li> 
     <li class="tit_price">单价（元）</li> 
     <li class="tit_quantity">数量</li> 
     <li class="tit_sum">小计（元）</li> 
     <li class="tit_action">操作</li> 

    </ul> 
    <!--商品--> 
    <!-- 无活动--> 
    <!-- 无合并 --> 
  <form action="{{url('/home/order/index')}}" method="get">
    @if($gwc == 1)
    <div style="padding:10px;font-size:28px;">您还没有添加任何商品,请去往<a href="/" style="color:red" target="_self">首页</a>添加</div>
    @else
      @foreach($goods as $k=>$v)
      <div class="cart_form c_clearfix"> 
       <div class="shopping_con" data-role="product" data-attr="{&quot;product_id&quot;:&quot;539581100&quot;,&quot;goods_id&quot;:&quot;70685&quot;,&quot;amt&quot;:&quot;1&quot;}"> 
        <div class="c_meg"> 
         <dl> 
          <dt> 
           <a href="/goods-70685.html"><img src="/uploads/{{$v->pic}}" width="78" height="78" /></a> 
          </dt> 
          <dd> 
           <p class="m_tit"><a href="/goods-70685.html">{{$v->goods_name}}</a></p> 
           <div>
              <span style="width:70px">颜色: {{str_replace([1,2,3,4,5,6,7],['红色','黄色','蓝色','绿色','黑色','白色'],$v->dingdan_color)}}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <span>尺码: {{str_replace([1,2,3,4,5],['S','M','L','XL','XXL'],$v->dingdan_size)}}</span>
           </div>
          </dd> 
         </dl> 
        </div> 
        <div class="c_price"> 
         &yen;<span class="c_price_jiage">{{$v->price}}</span>
        </div> 
        <div class="c_quantity" style="padding-right: 33px;"> 
         <div class="c_amount c_clearfix" style="width:80px">
         <input type="hidden" name="id[]" value="{{$v->id}}"> 
         <input type="hidden" name="dingdan_size[]" value="{{$v->dingdan_size}}">
         <input type="hidden" name="dingdan_color[]" value="{{$v->dingdan_color}}">
          <input type="hidden" name="key" value="{{$k}}">
          <a class="num_jian">-</a> 
          <input class="shuliang" name="amt[]" value="{{$v->num}}" type="text"/>
          <a class="num_jia">+</a>
        </div> 
        </div> 
        <div class="c_sum"> 
         &yen;<span class="c_sum_zongjia">{{$v->price*$v->num}}</span>
        </div> 
        <div class="c_action" style="margin-right:11px"> 
         <i ><img class="delete" src="/home/cart/Images/icons1.png" alt=""></i> 
        </div> 
        <div class="c_check"> 
         <input data-role="product" checked="checked" type="checkbox" />
        </div> 
       </div> 
       <!--赠品 list--> 
       <div class="c_gift"> 
        <ul class="gift_icon"> 
        </ul> 
       </div> 
      </div> 
      @endforeach
    @endif
    <!-- 分组 --> 
   </div> 
   <!--购物车 结算 --> 

   <div class="cart_con c_clearfix"> 
    <!--金额结算--> 
    <div class="c_balance"> 
     <!--计算--> 
     <div class="c_count"> 
      <p class="c_clearfix"><span class="c_rt">&yen;<i class="c_gouwu_zongjia">{{ $total }}</i></span><span class="c_lt">商品金额：</span><span class="c_piece">共<i>{{ $num_zong }}</i>件商品</span></p> 
      <p class="c_clearfix"><span class="c_rt">－&yen;<i class="fs_14">0</i></span></p> 
      <p class="c_clearfix"><span class="c_rt c_paid">&yen;<i class="c_gouwu_zongjia">{{ $total }}</i></span><span class="c_lt fw_b">实付金额：</span></p> 
     </div> 
     <!--计算/--> 
    </div> 
    <!--金额结算/--> 
    <!--结算按钮 浮动  fixed_bt --> 
    <div class="c_balance_bt fixed_bt"> 
     <div class="webz"> 
      <div class="b_check">
       <input data-role="all" checked="checked" type="checkbox" />
       <label>全选</label>
      </div> 
      <div class="b_del">
       <i></i>删除
      </div> 
      {{ csrf_field() }}
      <button class="balance_bt gouwu_jiesuan">立即结算</button> 
    </form>
      <div class="fixed_balance"> 
       <p class="c_clearfix fix_sum"> <span class="fix_piece">共<i>{{ $num_zong }}</i>件商品</span> <span>商品金额：&yen;<span class="c_gouwu_zongjia">{{ $total }}<span></span> </p> 
       <p class="c_clearfix sum_price"> <span class="fw_b">实付金额：</span> <span class="c_paid">&yen;<span class="c_gouwu_zongjia">{{ $total }}</span></span> </p> 
      </div> 
     </div> 
    </div> 
    <!--结算按钮/--> 
   </div> 
   <!--购物车 结算 /--> 
   <!--拆分结算弹窗--> 
   <!--拆分结算弹窗//--> 
@endsection
@section('myjs')
     <script type="text/javascript" src="/home/cart/Scripts/jquery-1.8.3.min.js"></script>
     <script type="text/javascript">
        $('.num_jia').click(function(){
            // alert('加法');
            var num = $(this).prev().val();
            num++;
            $(this).prev().val(num);
            //获取当前单价
            var new_zong = $(this).parents('.shopping_con').find('.c_price_jiage').html()*num;
            $(this).parents('.shopping_con').find('.c_sum_zongjia').html(new_zong);
            //购物车总共商品价格
            var total = 0;
           $('.shopping_con').each(function(){
            total += parseInt($(this).find('.c_sum_zongjia').html());
           })
           // console.log(total);
           $('.c_gouwu_zongjia').html(total);
           return false;

        });
        $('.num_jian').click(function(){
            // alert('减法');
            var num = $(this).next().val();
            num--;
            if(num < 1){
                num = 1;
            }
            $(this).next().val(num);
            var new_zong = $(this).parents('.shopping_con').find('.c_price_jiage').html()*num;
            $(this).parents('.shopping_con').find('.c_sum_zongjia').html(new_zong);

            //购物车总共商品价格
            var total = 0;
           $('.shopping_con').each(function(){
            total += parseInt($(this).find('.c_sum_zongjia').html());
           })
           console.log(total);
           $('.c_gouwu_zongjia').html(total);
           return false;
        });
        //数量限制
        $('.shuliang').blur(function(){
          var shuliang = $(this).val();
          var reg = /^\d+$/;
          if(!reg.test(shuliang)){
            $(this).val('1');
          }
        })
        //绑定删除购物车商品事件
        $('.delete').click(function(){
            // alert('删除');
             //获取数据的key值
              var key = $(this).parents('.shopping_con').find('input[name=key]').val();
              

             var dd = $(this);
            //发送ajax
            $.get("{{url('/cart/delete')}}",{key:key},function(data){
              console.log(data);
              if(data == 1){
                // alert('删除成功');
                dd.parents('.cart_form').remove();
                 // location.href="/home/cart/cart";
              }else{
                alert('添加失败');
              }
            });
            // return false;
        })
        
      </script>
@endsection
